#include <bits/stdc++.h>

using namespace std;

typedef long long ll;
typedef double db;
typedef unsigned long long ull;
typedef long double ldb;

#define in read()
#define pii pair<int,int>
#define fi first
#define se second
#define FILE(x) freopen(x".in","r",stdin);\
	freopen(x".out","w",stdout);
#define pb push_back
#define vec vector<int>

int read(){int x = 0,sgn = 1;char ch = getchar();for(;!isdigit(ch);ch = getchar()) if(ch == '-') sgn = -1;for(;isdigit(ch);ch = getchar()) x = (x<<1)+(x<<3)+(ch^48);return x*sgn;}

const int N = 1e5+10;

ll f[N][3];
int n;

int main (){
#ifndef ONLINE_JUDGE
	freopen("1.in","r",stdin);
#endif
	n = in; f[0][0] = 0; f[0][1] = f[0][2] = -1e18;
	for(int i = 1,x;i <= n;i++){
		x = in;
		f[i][0] = max(f[i-1][0],f[i-1][1]) + x;
		f[i][1] = max(f[i-1][1],f[i-1][2]) - x;
		f[i][2] = f[i-1][2] + x;
		if(x < 0) f[i][2] = max(f[i][2],f[i][1]),f[i][1] = max(f[i][0],f[i][1]);
	}
	printf("%lld\n",max(f[n][0],max(f[n][1],f[n][2])));
	return 0;
}
